package com.hhf.springboot.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhf.feiapicommon.model.entity.InterfaceInfo;
import com.hhf.feiapicommon.service.inner.InnerInterfaceInfoService;
import com.hhf.springboot.common.ErrorCode;
import com.hhf.springboot.exception.BusinessException;
import com.hhf.springboot.mapper.InterfaceInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @Author hhf
 * @Date 2024/10/10
 * @Description
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    @Override
    public InterfaceInfo getInterfaceInfoByMethodAndHostAndRoute(String method, String host, String route) {

        //1.参数校验
        if (StringUtils.isAnyBlank(method,host,route)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        //2.查询条件构造
        QueryWrapper<InterfaceInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("method",method);
        wrapper.eq("host",host);
        wrapper.eq("route",route);
        //3.查询
        InterfaceInfo interfaceInfo = interfaceInfoMapper.selectOne(wrapper);
        if (interfaceInfo == null){
            throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
        }
        //4.返回
        return interfaceInfo;
    }
}
